package main

import (
	doubleLinkList "ccc/line/doubleLineList"
	"ccc/line/line"
	"ccc/line/linkLine"
	"ccc/line/tree"
	"fmt"
)

var firstName = 0

var firstSignleName = 'a'

func main() {
	// demoLine()
	// demoSignleList()
	// demoDoubleLinkList()
	demoTree()
}

func demoTree() {
	t := &tree.BinaryNode{
		Data: "A",
		Lchild: &tree.BinaryNode{
			Data: "B",
			Lchild: &tree.BinaryNode{
				Data: "D",
			},
			Rchild: &tree.BinaryNode{
				Data: "C",
				Rchild: &tree.BinaryNode{
					Data: "H",
				},
			},
		},
		Rchild: &tree.BinaryNode{
			Data: "E",
			Lchild: &tree.BinaryNode{
				Data: "G",
			},
			Rchild: &tree.BinaryNode{
				Data: "F",
			},
		},
	}
	t.PreOrderTraverse(t)
	fmt.Println()
	t.InOrderTraverse(t)
	fmt.Println()
	t.PostOrderTraverse(t)
}

func demoLine() {
	l := line.Create()
	l.Add(1, fastNode())
	l.Add(2, fastNode())
	l.Add(3, fastNode())
	l.Add(4, fastNode())
	l.Append(fastNode())
	l.Remove(2)
	fmt.Println("FIRST", l.Get(1), l.Get(2), l.Get(3), l.Get(4))
	n := l.Get(2)
	fmt.Println(n, l.Proir(n), l.Next(n))
	l.Add(2, fastNode())
	fmt.Println("Second", l.Get(1), l.Get(2), l.Get(3), l.Get(4), l.Get(5))
	l.Clear()
	fmt.Println(l, l.IsEmpty())
	fmt.Print("虽然有值,但是取不到")
	fmt.Println(l.Get(1))
}

func demoSignleList() {
	sl := linkLine.Create()
	sl.Append(fastSingleNode())
	sl.Append(fastSingleNode())
	sl.Append(fastSingleNode())
	sl.Append(fastSingleNode())
	sl.Append(fastSingleNode())
	sl.Insert(6, fastSingleNode())
	sl.Insert(7, fastSingleNode())
	sl.Dd()
	// fmt.Println(sl., "???")
}

func demoDoubleLinkList() {
	fe := doubleLinkList.CreateDoubleLinkList(3)
	fe.Append(doubleLinkList.CreateDoubleLinkList(2))
	fe3 := doubleLinkList.CreateDoubleLinkList(1)
	fe.Insert(fe3)
	fe.Append(doubleLinkList.CreateDoubleLinkList(5))
	fe3.Dd()
	fmt.Println("-----------------------------------------")
	fe.Dd()
	fe4 := doubleLinkList.CreateDoubleLinkList(4)
	fe.C(fe4, 4)
	fe.Dd()
}

func fastSingleNode() *linkLine.SingleNode {
	r := linkLine.FastSingleNode(firstSignleName)
	firstSignleName++
	return r
}

func fastNode() *line.Node {
	firstName++
	return line.FastNode(firstName)
}
